﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iemtm.WeChat.Core.RabbitMQ
{
    /// <summary>
    /// rabitMQ -更新事件
    /// </summary>
    public class RabbitUpdateHelper
    {
        /// <summary>
        /// 更新在线
        /// </summary>
        /// <param name="enC"></param>
        /// <param name="enGS"></param>
        /// <param name="enG"></param>
        public static void UpdateOnLine(Collector enC, Generator enG)
        {
            //if (enC == null || enG == null) return;
            if (enC != null)
            {


                enC.BOnline = true;//在线状态
                enC.ltOnTime = DateTime.Now;//最近上线时间
                                            // enC.bRunning = true;//是否运行
            }


            if (enG != null)
            {

                enG.BOnline = true;
                // enG.bRunning = true;
            }




        }

        /// <summary>
        /// 更新离线
        /// </summary>
        /// <param name="enC"></param>
        /// <param name="enGS"></param>
        /// <param name="enG"></param>
        public static void UpdateOffLine(Collector enC, Generator enG)
        {
            //if (enC == null || enG == null) return;
            if (enC != null)
            {
                enC.BOnline = false;//在线状态
                enC.ltOnTime = DateTime.Now;//最近上线时间
                enC.bRunning = false;//是否运行
            }

            if (enG != null)
            {
                enG.BOnline = false;
                enG.bRunning = false;
            }
            // enG.ComputedStatus = 0;





        }

        /// <summary>
        /// 更新GPS
        /// </summary>
        /// <param name="enC"></param>
        /// <param name="enGS"></param>
        /// <param name="enG"></param>
        public static void UpdateGPS(UGPS u, Collector enC, Generator enG)
        {
            // if (enC == null || enG == null) return;
            if (enC != null)
            {
                enC.GPSLocTime = u.GPSTime;
                enC.GPSLocLat = u.GpsLat;
                enC.GPSLocLgt = u.GpsLgt;
                enC.BDLocLat = u.GpsLatBD;
                enC.BDLocLgt = u.GpsLgtBD;
                enC.LAC = u.LAC;
                enC.CellID = u.CellID;
            }
            if (enG != null)
            {
                enG.GPSLocTime = u.GPSTime;
                enG.GPSLocLat = u.GpsLat;
                enG.GPSLocLgt = u.GpsLgt;
                enG.BDLocLat = u.GpsLatBD;
                enG.BDLocLgt = u.GpsLgtBD;
                enG.LAC = u.LAC;
                enG.CellID = u.CellID;

            }

        }
        /// <summary>
        /// 更新状态 实时数据
        /// </summary>
        /// <param name="gc"></param>
        /// <param name="enC"></param>
        /// <param name="enG"></param>
        public static void UpdateState(GenCollBaseAreaPrj gc, Collector enC, Generator enG)
        {
            #region 采集器
            if (enC != null)
            {
                //enC.DTUID = gc.c.DTUID;
                enC.BOnline = gc.c.BOnline;
                //enC.CurDevServer = gc.c.CurDevServer;
                // enC.GensetNum = gc.c.GensetNum;////油机名称
                enC.Extension = gc.c.Extension;
                enC.LAC = gc.c.LAC;
                enC.CellID = gc.c.CellID;
                enC.GenStart = gc.c.GenStart;
                enC.GenStop = gc.c.GenStop;
                enC.RunningPeriod = gc.c.RunningPeriod;
                enC.KWpower = gc.c.KWpower;
                enC.GenRunTimes = gc.c.GenRunTimes;
                enC.GenRunPeriod = gc.c.GenRunPeriod;
                //enC.LastGenStop = gc.c.LastGenStop;
                //enC.LastGenBaseStation = gc.c.LastGenBaseStation;
                //enC.LastGenPlace = gc.c.LastGenPlace;
                //enC.LastLongitude = gc.c.LastLongitude;
                //enC.LastLatitude = gc.c.LastLatitude;
                //enC.BDLocLat = gc.c.BDLocLat;
                //enC.BDLocLgt = gc.c.BDLocLgt;
                //enC.GPSLocLat = gc.c.GPSLocLat;
                //enC.GPSLocLgt = gc.c.GPSLocLgt;
                //enC.GPSLocTime = gc.c.GPSLocTime;
                //enC.GPSLocType = gc.c.GPSLocType;
                enC.bGpsLoc = gc.c.bGpsLoc;
                enC.bGenOnce = gc.c.bGenOnce;
                //enC.ipaddr = gc.c.ipaddr;
                //enC.ltOnTime = gc.c.ltOnTime;
                //enC.ltOffTime = gc.c.ltOffTime;
                //enC.rBts = gc.c.rBts;
                //enC.sBts = gc.c.sBts;
                enC.bRunning = gc.c.bRunning;
                //enC.lastSaveWJ = gc.c.lastSaveWJ;
                //enC.LastCheckDt = gc.c.LastCheckDt;
                enC.Alarms = gc.c.Alarms;
                //enC.BaseStationCode = gc.c.BaseStationCode;
                //enC.BaseStationTTCode = gc.c.BaseStationTTCode;
                //enC.BaseStationName = gc.c.BaseStationName;
                //enC.BaseStationAddr = gc.c.BaseStationAddr;
                enC.GPSPOSITION = gc.c.GPSPOSITION;
                enC.HBI = gc.c.HBI;
                enC.SEEMINGMAIN = gc.c.SEEMINGMAIN;
                enC.CrankTimes = gc.c.CrankTimes;
                enC.KWenergy = gc.c.KWenergy;
                enC.TOTCURRENT = gc.c.TOTCURRENT;
                enC.ExtBATVolt = gc.c.ExtBATVolt;
                enC.LiBATVolt = gc.c.LiBATVolt;
                enC.GENALARM = gc.c.GENALARM;
                enC.BATLOWVOLTALARM = gc.c.BATLOWVOLTALARM;
                enC.GENVOLTL1 = gc.c.GENVOLTL1;
                enC.GENVOLTL2 = gc.c.GENVOLTL2;
                enC.GENVOLTL3 = gc.c.GENVOLTL3;
                enC.GENCURRENTL1 = gc.c.GENCURRENTL1;
                enC.GENCURRENTL2 = gc.c.GENCURRENTL2;
                enC.GENCURRENTL3 = gc.c.GENCURRENTL3;
                enC.CSQ = gc.c.CSQ;
                enC.INPUT1VOLT = gc.c.INPUT1VOLT;
                enC.INPUT2VOLT = gc.c.INPUT2VOLT;
                enC.INPUT3VOLT = gc.c.INPUT3VOLT;
                enC.RELAY1STATUS = gc.c.RELAY1STATUS;
                enC.RELAY2STATUS = gc.c.RELAY2STATUS;
                enC.RELAY4STATUS = gc.c.RELAY4STATUS;
                enC.RELAY3STATUS = gc.c.RELAY3STATUS;
                enC.MAINVOLT = gc.c.MAINVOLT;
                enC.MAINFREQ = gc.c.MAINFREQ;
                enC.GENFREQ = gc.c.GENFREQ;
                enC.GENVOLTL12 = gc.c.GENVOLTL12;
                enC.GENVOLTL23 = gc.c.GENVOLTL23;
                enC.GENVOLTL31 = gc.c.GENVOLTL31;
                enC.GENPHASEL12 = gc.c.GENPHASEL12;
                enC.GENPHASEL13 = gc.c.GENPHASEL13;
                enC.ACTIVEPOWER = gc.c.ACTIVEPOWER;
                enC.REACTIVEPOWER = gc.c.REACTIVEPOWER;
                enC.APPARENTPOWER = gc.c.APPARENTPOWER;
                enC.POWERFACTOR = gc.c.POWERFACTOR;
                enC.GENRECORDNUM = gc.c.GENRECORDNUM;
                enC.DATECLOCK = gc.c.DATECLOCK;
                enC.SWVER = gc.c.SWVER;
                enC.LastFuelValue = gc.c.LastFuelValue;
                enC.FuelDuration = gc.c.FuelDuration;
                enC.BFuelLowAlarm = gc.c.BFuelLowAlarm;
            }
            #endregion
            #region 油机
            if (enG != null)
            {
                enG.BOnline = gc.gen.BOnline;
                enG.LAC = gc.gen.LAC;
                enG.CellID = gc.gen.CellID;
                enG.bRunning = gc.gen.bRunning;
                enG.GenStart = gc.gen.GenStart;
                enG.GenStop = gc.gen.GenStop;
                enG.RunningPeriod = gc.gen.RunningPeriod;
                enG.KWpower = gc.gen.KWpower;
                enG.CrankTimes = gc.gen.CrankTimes;
                enG.OilConsume = gc.gen.OilConsume;
                enG.Alarms = gc.gen.Alarms;
                //enG.LastGenStop = gc.gen.LastGenStop;
                //enG.LastGenBaseStation = gc.gen.LastGenBaseStation;
                //enG.LastGenPlace = gc.gen.LastGenPlace;
                //enG.LastLongitude = gc.gen.LastLongitude;
                //enG.LastLatitude = gc.gen.LastLatitude;
                enG.GenVoltage = gc.gen.GenVoltage;
                enG.GenCurrent = gc.gen.GenCurrent;
                enG.GenFreq = gc.gen.GenFreq;
                enG.PowerFactor = gc.gen.PowerFactor;
                enG.ActivePower = gc.gen.ActivePower;
                //enG.BDLocLat = gc.gen.BDLocLat;
                //enG.BDLocLgt = gc.gen.BDLocLgt;
                //enG.GPSLocLat = gc.gen.GPSLocLat;
                //enG.GPSLocLgt = gc.gen.GPSLocLgt;
                //enG.GPSLocTime = gc.gen.GPSLocTime;
                enG.GPSLocType = gc.gen.GPSLocType;
                enG.bGpsLoc = gc.gen.bGpsLoc;
                enG.bGenOnce = gc.gen.bGenOnce;
                //enG.LastCheckDt = gc.gen.LastCheckDt;
                //enG.ltOnTime = gc.gen.ltOnTime;
                //enG.ltOffTime = gc.gen.ltOffTime;
                //enG.LGenRdSyncDt = gc.gen.LGenRdSyncDt;
                enG.SEEMINGMAIN = gc.gen.SEEMINGMAIN;
                enG.TOTCURRENT = gc.gen.TOTCURRENT;
                enG.ExtBATVolt = gc.gen.ExtBATVolt;
                enG.LiBATVolt = gc.gen.LiBATVolt;
                //enG.GENALARM = gc.gen.GENALARM;
                enG.BATLOWVOLTALARM = gc.gen.BATLOWVOLTALARM;
                //enG.BaseStationCode = gc.gen.BaseStationCode;
                //enG.BaseStationTTCode = gc.gen.BaseStationTTCode;
                //enG.BaseStationName = gc.gen.BaseStationName;
                //enG.Status = (enG.Status == 1 || enG.Status == 2 || enG.Status == 4) ? (gc.gen.Status == 1 && !gc.gen.bRunning ? 4 : gc.gen.Status) : enG.Status;
                enG.BFuelLowAlarm = gc.gen.BFuelLowAlarm;
            }
            #endregion
        }
        /// <summary>
        /// 更新状态 实时数据
        /// </summary>
        /// <param name="gc"></param>
        /// <param name="enC"></param>
        /// <param name="enG"></param>
        public static void UpdateRECORD(GenCollBaseAreaPrj gc, Collector enC, Generator enG)
        {
            #region 采集器
            if (enC != null)
            {

                enC.bGenOnce = gc.c.bGenOnce;
                enC.GenStart = gc.c.GenStart;
                enC.GenStop = gc.c.GenStop;
                enC.RunningPeriod = gc.c.RunningPeriod;
                enC.KWpower = gc.c.KWpower;

                enC.LastGenStop = gc.c.LastGenStop;
                enC.LastGenBaseStation = gc.c.LastGenBaseStation;
                enC.LastGenPlace = gc.c.LastGenPlace;
                enC.LastLatitude = gc.c.LastLatitude;
                enC.LastLongitude = gc.c.LastLongitude;

            }
            #endregion
            #region 油机
            if (enG != null)
            {
                enG.bGenOnce = gc.gen.bGenOnce;
                enG.GenStart = gc.gen.GenStart;
                enG.GenStop = gc.gen.GenStop;
                enG.RunningPeriod = gc.gen.RunningPeriod;
                enG.KWpower = gc.gen.KWpower;

                enG.LastGenStop = gc.gen.LastGenStop;
                enG.LastGenBaseStation = gc.gen.LastGenBaseStation;
                enG.LastGenPlace = gc.gen.LastGenPlace;
                enG.LastLatitude = gc.gen.LastLatitude;
                enG.LastLongitude = gc.gen.LastLongitude;
            }
            #endregion
        }

        /// <summary>
        /// 开机包
        /// </summary>
        /// <param name="gc"></param>
        /// <param name="enC"></param>
        /// <param name="enG"></param>
        public static void UpdateGENSTA(GenCollBaseAreaPrj gc, Collector enC, Generator enG)
        {
            #region 采集器
            if (enC != null)
            {
                //enC.DTUID = gc.c.DTUID;
                enC.bRunning = gc.c.bRunning;
                enC.BOnline = gc.c.BOnline;
                enC.GENVOLTL1 = gc.c.GENVOLTL1;
                enC.GENVOLTL2 = gc.c.GENVOLTL2;
                enC.GENVOLTL3 = gc.c.GENVOLTL3;
                enC.GENCURRENTL1 = gc.c.GENCURRENTL1;
                enC.GENCURRENTL2 = gc.c.GENCURRENTL2;
                enC.GENCURRENTL3 = gc.c.GENCURRENTL3;
                enC.TOTCURRENT = gc.c.TOTCURRENT;
                enC.GENFREQ = gc.c.GENFREQ;
                enC.ACTIVEPOWER = gc.c.ACTIVEPOWER;
                enC.KWenergy = gc.c.KWenergy;
                enC.CrankTimes = gc.c.CrankTimes;
                //enC.GensetNum = gc.c.GensetNum; //油机名称
                enC.Extension = gc.c.Extension;
                enC.GENALARM = gc.c.GENALARM;
                enC.SEEMINGMAIN = gc.c.SEEMINGMAIN;
                enC.GPSPOSITION = gc.c.GPSPOSITION;
                enC.BATLOWVOLTALARM = gc.c.BATLOWVOLTALARM;
                enC.INPUT3VOLT = gc.c.INPUT3VOLT;
                enC.GPSLocLat = gc.c.GPSLocLat;
                enC.GPSLocLgt = gc.c.GPSLocLgt;
                enC.BDLocLat = gc.c.BDLocLat;
                enC.BDLocLgt = gc.c.BDLocLgt;

            }
            #endregion
            #region 油机
            if (enG != null)
            {

                enG.BOnline = gc.gen.BOnline;

                enG.bRunning = gc.gen.bRunning;
                enG.GenCurrent = gc.gen.GenCurrent;

                enG.TOTCURRENT = gc.gen.TOTCURRENT;
                enG.GenFreq = gc.gen.GenFreq;
                enG.ActivePower = gc.gen.ActivePower;
                enG.KWenergy = gc.gen.KWenergy;
                enG.CrankTimes = gc.gen.CrankTimes;
                // enG.GensetNum = gc.gen.GensetNum; //油机名称
                enG.Extension = gc.gen.Extension;
                enG.GENALARM = gc.gen.GENALARM;
                enG.SEEMINGMAIN = gc.gen.SEEMINGMAIN;
                enG.GPSPOSITION = gc.gen.GPSPOSITION;
                enG.BATLOWVOLTALARM = gc.gen.BATLOWVOLTALARM;

                enG.GPSLocLat = gc.gen.GPSLocLat;
                enG.GPSLocLgt = gc.gen.GPSLocLgt;
                enG.BDLocLat = gc.gen.BDLocLat;
                enG.BDLocLgt = gc.gen.BDLocLgt;
            }
            #endregion
        }

        /// <summary>
        /// COMMON
        /// </summary>
        /// <param name="gc"></param>
        /// <param name="enC"></param>
        /// <param name="enG"></param>
        public static void UpdateCOMMON(GenCollBaseAreaPrj gc, Collector enC, Generator enG)
        {
            #region 采集器
            if (enC != null)
            {
                //enC.DTUID = gc.c.DTUID;
                enC.bRunning = gc.c.bRunning;
                enC.BOnline = gc.c.BOnline;
                enC.GENVOLTL1 = gc.c.GENVOLTL1;
                enC.GENVOLTL2 = gc.c.GENVOLTL2;
                enC.GENVOLTL3 = gc.c.GENVOLTL3;
                enC.GENCURRENTL1 = gc.c.GENCURRENTL1;
                enC.GENCURRENTL2 = gc.c.GENCURRENTL2;
                enC.GENCURRENTL3 = gc.c.GENCURRENTL3;
                enC.TOTCURRENT = gc.c.TOTCURRENT;
                enC.GENFREQ = gc.c.GENFREQ;
                enC.ACTIVEPOWER = gc.c.ACTIVEPOWER;
                enC.KWenergy = gc.c.KWenergy;
                enC.CrankTimes = gc.c.CrankTimes;
                // enC.GensetNum = gc.c.GensetNum; //油机名称
                enC.Extension = gc.c.Extension;
                enC.GENALARM = gc.c.GENALARM;
                enC.SEEMINGMAIN = gc.c.SEEMINGMAIN;
                enC.GPSPOSITION = gc.c.GPSPOSITION;
                enC.BATLOWVOLTALARM = gc.c.BATLOWVOLTALARM;
                enC.INPUT3VOLT = gc.c.INPUT3VOLT;
                enC.GPSLocLat = gc.c.GPSLocLat;
                enC.GPSLocLgt = gc.c.GPSLocLgt;
                enC.BDLocLat = gc.c.BDLocLat;
                enC.BDLocLgt = gc.c.BDLocLgt;

            }
            #endregion
            #region 油机
            if (enG != null)
            {

                enG.BOnline = gc.gen.BOnline;

                enG.bRunning = gc.gen.bRunning;
                enG.GenCurrent = gc.gen.GenCurrent;

                enG.TOTCURRENT = gc.gen.TOTCURRENT;
                enG.GenFreq = gc.gen.GenFreq;
                enG.ActivePower = gc.gen.ActivePower;
                enG.KWenergy = gc.gen.KWenergy;
                enG.CrankTimes = gc.gen.CrankTimes;
                //enG.GensetNum = gc.gen.GensetNum; //油机名称
                enG.Extension = gc.gen.Extension;
                enG.GENALARM = gc.gen.GENALARM;
                enG.SEEMINGMAIN = gc.gen.SEEMINGMAIN;
                enG.GPSPOSITION = gc.gen.GPSPOSITION;
                enG.BATLOWVOLTALARM = gc.gen.BATLOWVOLTALARM;

                enG.GPSLocLat = gc.gen.GPSLocLat;
                enG.GPSLocLgt = gc.gen.GPSLocLgt;
                enG.BDLocLat = gc.gen.BDLocLat;
                enG.BDLocLgt = gc.gen.BDLocLgt;
            }
            #endregion
        }


    }
}
